package com.gupaoedu.vip.netty.io.nio.channel;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @program:gupaoedu-vip-netty-io
 * @description:Filechannel demo
 * @author:Gongchao
 * @date:2020-04-27
 **/
public class FileOutputDemo {

    static private final byte message[] = { 83, 111, 109, 101, 32, 98, 121, 116, 101, 115, 46 };

    public static void main(String[] args) throws Exception {
        FileOutputStream fos = new FileOutputStream("D://test.txt");

        FileChannel fc = fos.getChannel();

        ByteBuffer buffer = ByteBuffer.allocate(1024);

        for(int i = 0 ; i < message.length ;i ++) {
            buffer.put(message[i]);
        }

        buffer.flip();

        fc.write(buffer);

        fos.close();

        fc.close();



    }
}
